package com.example.bookmanagementsystem.mapper;

import com.example.bookmanagementsystem.entity.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookInfoMapper {
    @Select("select * from book_info where status != 0 order by book_info.id desc limit #{offset}, #{PageSize}")
    List<BookInfo> selectBookInfoByPage(Integer offset, Integer PageSize);

    @Select("select count(*) from book_info where status != 0")
    Integer countOfBook();

    @Select("select * from book_info where book_info.id = #{id}")
    BookInfo selectBookInfoById(Integer id);

    @Insert("insert into book_info (book_name, author, count, price, publish, status) " +
            "values (#{bookInfo.bookName}, #{bookInfo.author}, #{bookInfo.count}, #{bookInfo.price}, #{bookInfo.publish}, #{bookInfo.status})")
    Integer insertBook(@Param("bookInfo") BookInfo bookInfo);

    Integer updateBook(@Param("bookInfo") BookInfo bookInfo);

    Integer batchDelete(List<Integer> ids);
}
